<template>
	<view>
		<u-navbar :border-bottom="false" title="企业设置" :title-size="36" :title-bold="true" :title-color="textColor" :background="{background: '#ffffff'}" :customBack="back">
		</u-navbar>
		<view class="u-m-b-20 " style="background-color: #fff;overflow: hidden;">
			<image :src="avatar" mode="" style="width: 120rpx;height: 120rpx; border-radius: 50%;margin: 30rpx auto;display: block;"></image>
			<view class="u-font-32 u-text-center" style="font-weight: 500;">{{shopName}}</view>
			<view class="erweima u-m-t-18 u-m-b-18 u-flex u-row-center" @click.stop="getShopCode">
				<image src="/static/erweima.png" style="width: 38rpx;height: 38rpx;" mode=""></image>
			</view>
		</view>
		<view class="u-m-b-20">
			<u-cell-group :title-style="titleStyle" :border="false">
				<u-cell-item title="企业图标" value="修改图标" @tap="toPage('touxiang')"></u-cell-item>
				<u-cell-item title="营业执照" :value="storeShop.businessLicenseResourceId ? '已上传':'未上传'" :arrow="false" @click="toPage('profile')">
					<view slot="right-icon" ><u-icon name="arrow-right" :size="35" color="#FFFFFF"></u-icon></view>
				</u-cell-item>
			
			</u-cell-group>
		</view>
		<view class="u-m-b-20" >
			<u-cell-group :title-style="titleStyle" :border="false">
			<!-- 	<u-cell-item title="发票" value="配置发票信息" :border-bottom="false" @click="toPage('fapiao')"></u-cell-item>
				<u-cell-item title="收货地址" value="配置收货地址" @click="toPage('dizhi')"></u-cell-item> -->
				<u-cell-item title="职位管理" value="设置店长、销售等职位" @click="toPage('zhiwei')"></u-cell-item>
				<u-cell-item title="员工管理" value="管理店内员工" @click="toPage('yuangong')"></u-cell-item>
			</u-cell-group>
		</view>
		<view class="u-m-b-20" >
			<u-cell-group :title-style="titleStyle" :border="false">
				<u-cell-item title="企业注销" :border-bottom="false" @click="$u.toast('请联系客服处理')"></u-cell-item>
				<!-- <u-cell-item title="企业转移" :border-bottom="false"></u-cell-item> -->
			</u-cell-group>
		</view>
		
		<view class="u-m-b-20" v-if="isPurchase">
			<u-cell-group :title-style="titleStyle" :border="false">
				<u-cell-item  @click="toSetPage('purchase')" >
					<template #title>
						<view class="u-flex ">
							<image src="/static/mendian/purchaseSet.png" mode="" style="width: 102rpx;height: 102rpx;"></image>
							<view class="u-m-l-20">
								<view class="u-font-30" style="font-weight: 500;">采购设置</view>
								<text class="u-font-26" style="color: #999;">发票信息、收货地址、采购合约</text>
							</view>
						</view>
					</template>
				</u-cell-item>
			</u-cell-group>
		</view>
		<view class="u-m-b-20" v-if="isSale">
			<u-cell-group :title-style="titleStyle" :border="false">
				<u-cell-item  @click="toSetPage('sale')">
					<template #title>
						<view class="u-flex ">
							<image src="/static/mendian/saleSet.png" mode="" style="width: 102rpx;height: 102rpx;"></image>
							<view class="u-m-l-20">
								<view class="u-font-30" style="font-weight: 500;">销售设置</view>
								<text class="u-font-26" style="color: #999;">开通收款方式、运费模板、销售合约</text>
							</view>
						</view>
					</template>
				</u-cell-item>
			</u-cell-group>
		</view>
		<view class="u-m-b-20" v-if="isOwners">
			<u-cell-group :title-style="titleStyle" :border="false">
				<u-cell-item  @click="toPage('zhiwei')" >
					<template #title>
						<view class="u-flex ">
							<image src="/static/mendian/ownerSet.png" mode="" style="width: 102rpx;height: 102rpx;"></image>
							<view class="u-m-l-20">
								<view class="u-font-30" style="font-weight: 500;">品牌商设置</view>
							</view>
						</view>
					</template>
				</u-cell-item>
			</u-cell-group>
		</view>
		<akLoading isFullScreen :active="loading"></akLoading>
		<!-- 二维码显示 -->
		<u-modal v-model="erweimaShow" width="60%" :show-title="false" :show-confirm-button="false" :show-cancel-button="false" :mask-close-able="true">
			<view class="slot-content">
				<view class="u-text-center u-m-t-20">
					企业二维码
				</view>
				<img :src="erweima" style="width: 100%;" mode="" />
			</view>
		
		</u-modal>
	</view>
</template>

<script>
	import { useShopStore } from '@/store/shop.js';
	import { mapState } from 'pinia';
	export default {
		data() {
			return {
				titleStyle: {
					fontSize: '30rpx',
				},
				shopId:'',
				shopName:'',
				avatar:'',
				businessLicenseResourceId:"",
				erweimaShow:false,
				erweima:'',
				loading:false,
				isPurchase:false,
				isSale:false,
				isOwners:false,
			}
		},
		onLoad(options) {
			this.shopId = options.id
			this.shopInfoInitFn();
		},
		onShow(){
			this.shopInfoInitFn();
		},
		created() {
		},
		computed:{
			...mapState(useShopStore, {storeShop: 'shop'})
		},
		methods: {
			async shopInfoInitFn(){
				console.log(123123);
				this.loading = true;
				const res = await this.$setHttp.get('api/Shop/GetShop?id='+this.shopId,{header:{shopId:this.shopId}});
				this.loading = false;
				if(res.code === 200){
					this.shopName = res.data.name;
					this.businessLicenseResourceId = res.data.businessLicenseResourceId;
					this.isPurchase = res.data.purchase;
					this.isSale = res.data.sale;
					// if(res.data.shopLevels!=null){
					// 	this.shopLevels = res.data.shopLevels;
					// }
					// this.avatar=this.resourcesUrl+(res.data.logoResourceId==null?'00000000-0000-0000-0000-000000000002':res.data.logoResourceId);
						this.avatar=res.data.logoUrl?res.data.logoUrl:this.defaultLogo;
				}else{
					this.$u.toast('获取企业信息失败，请退出重试')
				}
			},
			async getShopCode(){
				const res = await this.$setHttp.get('api/Shop/GetShopQrCode', { header:{shopId:this.shopId},responseType: 'arraybuffer',params:{shopId:this.shopId}})
				this.erweima = 'data:image/jpeg;base64,'+ uni.arrayBufferToBase64(res);
				this.erweimaShow = true;
			},
			toPage(page) {
				let avatar = '';
				if(page == 'touxiang'){
					avatar = '&avatar='+ this.avatar;
				}
				this.$mRouter.push({
					route: '/pages/purchase/shezhi/' + page+'?shopId='+this.shopId+avatar
				})
			},
			toSetPage(type){
				console.log(type);
				let index =type == 'sale'?'/index':'';
				this.$mRouter.push({
					route: '/pages/'+type+'/shezhi'+index+'?id='+this.shopId
				})
			},
			back() {
				// this.$mRouter.reLaunch({ route: '/pages/mine/index' })
				uni.reLaunch({
					url: '/pages/mine/index'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
</style>
